*Analysis Do-File for creating Figures 2
	*Figures are separated in to 2a,b,c,d
*Runs event study regressions and produces graphs of effects over time

***File set-up
macro drop _all
mat drop _all
eststo clear
estimates clear
global path "[ENTER PATH HERE]"
global figs "$path\REStat Replication V2\Figures"
global log "$path\REStat Replication V2\Log Files"
set scheme lean2

clear
set more off

cap log close
log using "$log\figure_2.txt", replace text
use "$path\REStat Replication V2\Data\master_data_analysis_subset"

*Set folder for main figures
cd "$figs"



***Loops through arrest types, producing the estimates that go into Figure 2
foreach var of varlist all_crimes index_violent index_property lowMB {
	
	*If arrest is for part 1 offense (see if statement), ensure that crime data is non-missing
	if inlist("`var'", "all_crimes", "index_violent", "index_property")  {
		di "------Reg `var' arrests------"
		reghdfe ln_`var' ln_pop_s ///
			qtr_neg4_binned-qtr_neg2  qtr_0-qtr_6_binned ///
			if !inlist(., ln_actual_`var', ln_actual_index_violent, ln_actual_index_property) ///
			, cl(group_ori) absorb(group_ori month_year)
			
		*Call plot code
		qui do "$path\REStat Replication\Code\coef_plot_quart"
			
		*Plot the normalized coefficents and SEs
		*Normalized to the quarter right before officer-involved fatality
		qui coefplot mat(coef_1000[,1]), vertical yline(0) se(2)  /// 
			yscale(range(-0.5 0.1))  ylabel(-0.5(0.1)0.1, glcolor(gs12)) ///
			msize(large) msymbol(O) mfcolor(black%100) mcolor(white%0) ///
			xtitle(Quarter Relative to Event) ytitle(Log Points) ///
			xline(3.5, lpattern(dash) lcolor(red) axis(1))
		if "`var'" == "all_crimes" {
			graph export "figure_2a.pdf", replace
		}
		else if "`var'" == "index_violent" {
			graph export "figure_2b.pdf", replace
		}
		else if "`var'" == "index_property" {
			graph export "figure_2c.pdf", replace			
		}

	}
	else {
		***Analysis by qtr for extended event window w/o Part I offense ctrl
		di "------Reg `var' arrests w/o crime controls------"
		reghdfe ln_`var' ln_pop_s ///
			qtr_neg4_binned-qtr_neg2  qtr_0-qtr_6_binned ///
			if !inlist(., ln_actual_index_violent, ln_actual_index_property) ///
			, cl(group_ori) absorb(group_ori month_year)
			
		*Call plot code
		qui do "$path\REStat Replication\Code\coef_plot_quart"
			
		*Plot the normalized coefficents and SEs
		*Normalized to the quarter right before officer-involved fatality
		qui coefplot mat(coef_1000[,1]), vertical yline(0) se(2)  /// 
			yscale(range(-0.5 0.1))  ylabel(-0.5(0.1)0.1, glcolor(gs12)) ///
			msize(large) msymbol(O) mfcolor(black%100) mcolor(white%0) ///
			xtitle(Quarter Relative to Event) ytitle(Log Points) ///
			xline(3.5, lpattern(dash) lcolor(red) axis(1))
		graph export "figure_2d.pdf", replace
	
	}
}


cap log close

